home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8500 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: chronicle.mti.sgi.com!news
  2. From: austern@isolde.mti.sgi.com (Matt Austern)
  3. Newsgroups: comp.lang.c++,comp.lang.c
  4. Subject: Re: Performance: C vs. C++
  5. Date: 15 Feb 1996 23:04:52 GMT
  6. Organization: SGI
  7. Message-ID: <AUSTERN.96Feb15150452@isolde.mti.sgi.com>
  8. References: <30F6BAAC.12B5@iastate.edu> <4da9pn$a45@news.bridge.net>
  9.     <AUSTERN.96Feb15134314@isolde.mti.sgi.com>
  10.     <4g0cgt$a3l@stc06.ctd.ornl.gov>
  11. Reply-To: austern@mti.sgi.com
  12. NNTP-Posting-Host: isolde.mti.sgi.com
  13. In-reply-to: kennel@msr.epm.ornl.gov's message of 15 Feb 1996 22:36:13 GMT
  14.  
  15. In article <4g0cgt$a3l@stc06.ctd.ornl.gov> kennel@msr.epm.ornl.gov (Matt Kennel) writes:
  16.  
  17. > > And if you do have a pointer to a polymorphic class, and you want to
  18. > > call a virtual function and ensure that you're calling the base 
  19. > > class's version, that's actually possible: instead of writing
  20. > > base_pointer->f(), you write base_pointer->base::f().  The syntax
  21. > > is ugly, to be sure, but it doesn't bother me that you have to use
  22. > > ugly syntax for such a rare operation.
  23. > Does it work with []??
  24. > I.e.
  25. >     MyMatrix x;
  26. >     x[3][2] = 4; 
  27.  
  28. Yes, but only at the cost of even uglier syntax.  I'm going to pretend
  29. that matrix reference is x(3,2) instead of x[3][2]: you need to jump
  30. through too many hoops if you want to use the x[3][2] form.  (For
  31. those who aren't C++ experts, what you have to do is define an
  32. auxiliary class.)
  33.  
  34. If x is a reference to a polymorphic base class MatrixBase, and
  35. if operator() is a virtual function, then you can call the base
  36. class version explicitly by writing 
  37.     x.MatrixBase::operator()(3,2) = 4.
  38.  
  39. In general, x(3,2) is equivalent to x.operator()(3,2).  It's only when
  40. you're performing unusual operations, though (like suppressing 
  41. run-time dispatch of a virtual function), that you need to write out
  42. x.operator()(3,2) explicitly.
  43. -- 
  44. Matt Austern
  45. SGI: MTI Compilers Group
  46. austern@isolde.mti.sgi.com
  47.